#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
#define Pi 3.1415926
int main()
{
	float width = 1000;
	float hight = 1000;
	float r = 50;
	float angle = 0;
	float l = 200;
	float anglespeed = Pi / 180;
	int i = 0;
	float a[1000];
	int n = 0;

	initgraph(width, hight);
	setbkcolor(RGB(255, 125, 0));
	BeginBatchDraw();
	while (1)
	{
		cleardevice();
		setlinestyle(PS_SOLID, 3);
		setlinecolor(HSVtoRGB(0, 0, 0));
		line(0, hight / 2, l, hight / 2);
		if (_kbhit()) {
			char input = _getch();
			if (input == ' ')
			{
				a[n] = Pi;
				n++;
			}
		}
		if (n > 0) {
			setlinecolor(HSVtoRGB(0, 1, 1));
			line(width / 2 + r * cos(a[n - 1]), hight / 2 + r * sin(a[n - 1]), width / 2 + (r + l) * cos(a[n - 1]), hight / 2 + (r + l) * sin(a[n - 1]));
			a[n - 1] = a[n - 1] + anglespeed;
		}
		if (a[n - 1] >= 2 * Pi) {
			a[n - 1] = a[n - 1] - 2 * Pi;
		}
		setlinecolor(HSVtoRGB(220, 1, 1));
		for (i = 0; i < n - 1; i++) {
			line(width / 2 + r * cos(a[i]), hight / 2 + r * sin(a[i]), width / 2 + (r + l) * cos(a[i]), hight / 2 + (r + l) * sin(a[i]));
			a[i] = a[i] + anglespeed;
			if (a[i] >= 2 * Pi) {
				a[i] = a[i] - 2 * Pi;
			}
			if ((a[n - 1] - a[i]) * (a[n - 1] - a[i]) < 0.002) {
				system("pause");
			}
		}
		setbkcolor(HSVtoRGB((n * 5) % 360, 0, 1));
		setfillcolor(HSVtoRGB((180 + n * 5) % 360, 1, 1));
		fillcircle(width / 2, hight / 2, r);
		settextcolor(HSVtoRGB(0, 0, 0));
		TCHAR s[20];//定义字符串数组
		swprintf_s(s, _T("%d"), n);//将score转换为字符串
		settextstyle(50, 0, _T("宋体"));//设置文字大小、字体
		outtextxy(50, 30, s);//输出得分文字

		FlushBatchDraw();
		Sleep(10);
	}
	_getch();
	closegraph();
	return 0;
}